<script LANGUAGE="JavaScript">
<!--

function exportWeka(options)
{
	var now = new Date();
	var nowString = now.getHours() + '-' + now.getMinutes() + '-' + (now.getMonth() + 1) + '-' + now.getDate() + '-' + now.getFullYear(); 
	var w = window.open('', '', 'width=400,height=400,resizeable,scrollbars');
	var content = '% \n';
	var dataContent = '';

	var numConversations = <c:out value="${fn:length(conversations)}"/>
	var numMessages = 0;
	var numDialogueActs = 0;

	var FUNCTION = 0x0; /* not used... just to remind */
	var DOMAIN = 1;
	var PREV1 = 2;
	var NEXT1 = 4;
	var PREV2 = 8;
	var NEXT2 = 16;

	var dataContent = '';

	<c:forEach items="${conversations}" var="conversation">
	  <c:forEach items="${conversation.messages}" var="message">
	  numMessages++;
	    <c:forEach items="${message.dialogueActs}" var="dialogueAct">
	      numDialogueActs++;
	      if (options & DOMAIN) {
		      dataContent += '<c:out value="${dialogueAct.domain.label}" />';
		      if (options & PREV1)	
			      dataContent += ', ' + '<c:out value="${dialogueAct.previousDialogueActDomainLabel}" />';
		      if (options & NEXT1)	
			      dataContent += ', ' + '<c:out value="${dialogueAct.nextDialogueActDomainLabel}" />';
		      dataContent += ', ';
	      } else	{		   
		      dataContent += '<c:out value="${dialogueAct.function.label}" />';	   
		      if (options & PREV1)	
		        dataContent += ', ' + '<c:out value="${dialogueAct.previousDialogueActFunctionLabel}" />';
		      if (options & NEXT1)	
			      dataContent += ', ' + '<c:out value="${dialogueAct.nextDialogueActFunctionLabel}" />';
		      dataContent += ', ';
	      }   
	      dataContent += '<c:out value="${conversation.conversationId}" />' + ', ';
	      dataContent += '<c:out value="${dialogueAct.message.messageId}" />' + ', ';
	      dataContent += '<c:out value="${dialogueAct.message.sequence}" />' + ', ';
	      dataContent += '<c:out value="${dialogueAct.message.speaker}" />' + ', ';
	// dataContent += '<c:out value="${dialogueAct.adjacency.label}" />' + ', ';
	      dataContent += '\'<c:out value="${dialogueAct.textSegment}" />\'' + '\n';		 
    	</c:forEach>
	  </c:forEach>
	</c:forEach>

	content += '% ARFF file generated by Conversation Annotation Environment \n';
	content += '% ' + nowString + '\n'; 
	content += '% Number of conversations: ' + numConversations + '\n';
	content += '% Number of messages: ' + numMessages + '\n';
	content += '% Number of dialogue acts: ' + numDialogueActs + '\n'; 
	content += '% \n';
	content += '@relation conversation_' + nowString + '\n';


	if (options & DOMAIN) {
		content += '@attribute attr_domain {';
		<c:forEach items="${da_domains}" var="domain">
		content += '<c:out value="${domain.label}"/>' + ',';
		</c:forEach>
		content += '} \n';
		
		if (options & PREV1) {
			content += '@attribute attr_prev_domain {';
			<c:forEach items="${da_domains}" var="domain">
			content += '<c:out value="${domain.label}"/>' + ',';
			</c:forEach>
			content += 'START1, NA';
			content += '} \n';
		}
		if (options & NEXT1) {
			content += '@attribute attr_next_domain {';
			<c:forEach items="${da_domains}" var="domain">
			content += '<c:out value="${domain.label}"/>' + ',';
			</c:forEach>
			content += 'END1, NA' ;
			content += '} \n';
		}
	} else {
		content += '@attribute attr_function {';
		<c:forEach items="${da_functions}" var="function">
		content += '<c:out value="${function.label}"/>' + ',';
		</c:forEach>
		content += '} \n';
		
		if (options & PREV1) {
			content += '@attribute attr_prev_function {';
			<c:forEach items="${da_functions}" var="function">
			content += '<c:out value="${function.label}"/>' + ',';
			</c:forEach>
			content += 'START1';
			content += '} \n';
		}

		if (options & NEXT1) {
			content += '@attribute attr_next_function {';
			<c:forEach items="${da_functions}" var="function">
			content += '<c:out value="${function.label}"/>' + ',';
			</c:forEach>
			content += 'END1';
			content += '} \n';
		}
	}
	
	content += '@attribute attr_conversationId numeric \n';
	content += '@attribute attr_messageId numeric \n';
	content += '@attribute attr_sequence numeric \n';
	content += '@attribute attr_speaker {1, 2} \n';

	content += '@attribute attr_text string \n';

	content += '@data \n';  
	content += dataContent;

	w.document.write(content);
	w.document.close(); 
}

//-->
</script>